package com.share.user.api;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.RequiresLogin;
import com.share.common.security.utils.SecurityUtils;
import com.share.user.domain.UserInfo;
import com.share.user.service.IUserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.share.common.core.context.SecurityContextHolder.getUserId;

@RestController
public class UserInfoApiController extends BaseController {
    @Autowired
    private IUserInfoService userInfoService;
    //微信授权登录-远程调用

    @Operation(summary = "小程序授权登录")
    @GetMapping("/userInfo/wxLogin/{code}")
    public R<UserInfo> wxLogin(@PathVariable("code") String code) {
        return R.ok(userInfoService.wxLogin(code));
    }

    @Operation(summary = "更新用户登录信息")
    @PutMapping("/userInfo/updateUserLogin")
    public R<Boolean> updateUserLogin(@RequestBody UpdateUserLogin updateUserLogin)
    {
        return R.ok(userInfoService.updateUserLogin(updateUserLogin));
    }

    @Operation(summary = "是否免押金")
    @RequiresLogin
    @GetMapping("/userInfo/isFreeDeposit")
    public AjaxResult isFreeDeposit() {
        return success(userInfoService.isFreeDeposit());
    }

    //获取用户信息
    @Operation(summary = "获取用户的详细信息")
    @GetMapping("/getUserInfo/{userId}")
    public R<UserInfo> getInfo(@PathVariable Long userId){
        return R.ok(userInfoService.getById(userId));
    }

    @GetMapping(value = "/userInfo/getUserCount")
    public R<Map<String, Object>> getUserCount() {
        Map<String, Object> map = userInfoService.getUserCount();
        return R.ok(map);
    }
}
